<?php

require_once 'Zend/Loader.php';

/**
 * Sistemi Config Loader
 *
 */
class MiniCMS_ConfigLoader {


	public function __construct() {
	
		/**
		 * include Zend_Config_Ini
		 */
		Zend_Loader::loadClass('Zend_Config_Ini');
		// il secondo parametro di Zend_Config_Ini è la sezione del file INI che legge 
		$config = new Zend_Config_Ini('../etc/miniCMS.conf', 'development');
		
		/**
		 * Include Zend-Registry
		 */
		Zend_Loader::loadClass('Zend_Registry');
		Zend_Registry::set('config', $config);


                /**
		 * Include Definition for Zend_Controller_Action class
		 */
		Zend_Loader::loadClass('Zend_Controller_Action');
		
		/**
		 * Load DB classes
		 */
		Zend_Loader::loadClass('Zend_Db');
		Zend_Loader::loadClass('Zend_Db_Table_Abstract');
		
		Zend_Loader::loadClass('Zend_View');
		
		$ZendView = new Zend_View();
		
		$ZendView->setScriptPath( $config->templates->common );
		$ZendView->addScriptPath( Zend_Registry::get('config')->templates->common );
		
		Zend_Registry::set('view', $ZendView);
		
		/*
		 * Load Queries
		 */
		$queries = new Zend_Config_Ini ("../etc/Sql/miniCmsMainSQL.sql", "default");
		
		Zend_Registry::set( 'sql', $queries );
		
		/**
		 * Calls classe's files
		 *
		 * @param	String	$className
		 */
		function __autoload ( $className ){
		    $className = str_replace(' ', '_', ucwords( str_replace('_', ' ', $className) ) );
    		$file = str_replace( '_', '/', $className );
		    if ( is_file( '../lib/' . $file . ".php" ) ){		    
		    	include_once '../lib/' . $file . ".php" ;
			}else {
				Zend_Loader::loadClass( $className );
			}
		}

	}

}

?>